<?php
class Loader
{
	private static $invisibleFileNames = array(".", "..", ".htaccess", ".htpasswd", ".svn", ".settings", "public", "demo", "samples", "view");
    private static $extension = '.helper.php';

	public function __construct()
    {
        $dir = self::scanDirectories('.');
        $str = '';
        foreach ($dir as $d)
        {
            $str .= PATH_SEPARATOR.$d;
        }
        set_include_path($str);
        spl_autoload_register(array("Loader","load"));
    }

    public static function load($class)
    {
        spl_autoload_extensions('.php, .inc.php');
        spl_autoload($class);
    }

    public static function scanDirectories($rootDir, $allData=array())
    {
        $dirContent = scandir($rootDir);
        foreach($dirContent as $key => $content)
        {
            $path = $rootDir.'/'.$content;
            if(!in_array($content, self::$invisibleFileNames))
            {
                if(is_dir($path) && is_readable($path))
                {
                    $allData[] = $path;
                    $allData = self::scanDirectories($path, $allData);
                }
            }
        }

        return $allData;
    }

	public static function loadHelper($helper)
	{
		if(is_array($helper))
		{
			foreach($helper as $help)
			{
				if(!function_exists(strtolower($help).'Init'))
				{
					require_once LIBRARY . 'helpers/' . $help . self::$extension;
				}
			}
		}
		else
		{
			if(!function_exists(strtolower($helper).'Init'))
			{
				require_once LIBRARY . 'helpers/' . $helper . self::$extension;
			}
		}
	}
}
    $loader = new Loader();

    // pre-carregamento dos helpers
    Loader::loadHelper(array(
    	'html', 'validation', 'tag', 'javascript', 'url'
    ));
?>